<template>
    <div>
        <h1>会员权益添加</h1>
        <a href="/DJ">返回</a>
        <table class="table">
            <tbody>
                <tr>
                    <td>等级名称</td>
                    <td>
                        <input type="text" v-model="data.Dname" disabled>
                    </td>
                </tr>

                <tr>
                    <td>权益</td>
                    <td>
                        <span v-for="d in finds">
                            <input type="checkbox" v-model="ids" :value="d.Qyname">{{ d.Qyname }}
                        </span>
                    </td>
                </tr>

                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" @click="Add">
                    </td>
                </tr>
            </tbody>
        </table>


    </div>
</template>

<script setup lang="ts">

import {ref,onMounted} from 'vue';
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';

var touer=useRouter();
var toue=useRoute();

//等级model
const data=ref({
    "Did": 0,
  "Dname": "",
  "State": true,
  "Qyname": ""
})

const ids=ref([]);

//添加
const Add=()=>{
    debugger;
    data.value.Qyname=ids.value.toString();
    axios.post("https://localhost:7185/api/DJ/UptQYAdd",data.value).then(res=>{
        if(res.data>0){
            alert("添加权益成功");
            touer.push({path:"/DJ"});
        }else{
            alert("添加权益失败");
            return;
        }
    })
}

//权益
const finds=ref([{
    "Qid": 1,
    "Qyname": "",
    "State": true,
    "Qysm": ""
}])

//钩子
onMounted(() => {
    QY();  
    Ft();
})



//反填
const Ft=()=>{
    axios.get("https://localhost:7185/api/DJ/GetFT",{params:{id:toue.query.id}}).then(res=>{
        data.value=res.data;
        ids.value=data.value.Qyname.split(',');
    })
}


//获取权益
const QY=()=>{
    axios.get("https://localhost:7185/api/DJ/GetQy").then(res=>{
        finds.value=res.data;
    })
}



</script>

<style scoped>

</style>